<% include head.ejs%>
<body>
<div class="wp">
    <header class="t-header">
        <div class="topbar">
            <a href="/order/preshop" class="gobakA fl">
                <i class="icon-angle-left"></i>
            </a>
            <a class="moreA fr">
                <i></i>
            </a>
            <span>订单确认</span>
        </div><!-- topbar end -->
    </header>

    <div class="orderBody shAddress mt20">
        <a href="/order/maddress" class="pr">
            <div class="user">
                收货人：<span class="name"><% if(addr.length>0){%><%= addr[0].receiver%> ，<%}%></span><span class="phone"><% if(addr.length>0){%><%= addr[0].receiver%><%}%></span>
            </div>
            <div class="adds">
                收货地址：<span class="dz"><% if(addr.length>0){%><%= addr[0].province+addr[0].city+addr[0].county+addr[0].detail%><%}%></span>
            </div>
            <i class="icon-angle-right"></i>
        </a>
    </div>

    <div class="orderBody orderinfo mt20">

            <% for(var i in ordInfo){%>
                <div id='<%= ordInfo[i].ord_id%>' class="spinfos cd-bouncy-nav-trigger">
                    <a href="#" class="clearfix">
                        <img src="<%= ordInfo[i].product_icon%>">
                        <div class="txt">
                            <h1><%= ordInfo[i].product_name%></h1>
                            <span>规格：<font class="zl"><%= ordInfo[i].value%></font></span>
                        </div>
                        <div class="ns clearfix">
                            <i>￥<%= ordInfo[i].prod_price * ordInfo[i].prod_sum/100%></i>
                            <span class="fr">x<%= ordInfo[i].prod_sum%></span>
                        </div>
                    </a>
                </div>
            <%}%>

        <div class="yfei clearfix">
            <div class="tit fl">运费</div>
            <div class="price fr">￥<%= freight[0].sendfee/100%></div>
        </div>
    </div>

    <div class="orderBody mt20">
        <div class="tit">优惠券</div>
        <div class="payBox">
            <li>
                    <span class="chkbody">
                        <input class="chkInput" id="coupon" type="checkbox" checked>
                        <label class="chkInputLb" for="coupon"></label>
                    </span>
                <span class="coupon" style="background: url("<%= %>")"></span>
            </li>
        </div>
    </div>

    <div class="orderBody payType mt20">
        <div class="tit">支付方式</div>
        <div class="payBox">
            <li>
                    <span class="chkbody">
                        <input class="chkInput" id="wxPaySel" type="checkbox" checked>
                        <label class="chkInputLb" for="wxPaySel"></label>
                    </span>
                <span class="wechatPay">微信支付</span>
            </li>
        </div>
    </div>

    <div class="iosBody"></div>

    <div class="btm-orderSubmit clearfix">
        <span class="orderInfos fl">总计：<font>￥<%= totalmoney/100%></font></span>
        <a id="payOrder" class="odSuni fr">
            提交订单
        </a>
    </div>


</div>

<div class="cd-bouncy-nav-modal">
    <nav>
        <ul class="cd-bouncy-nav">
            <li><a id="cancel">取消</a></li>
            <li><a id="del">删除</a></li>
        </ul>
    </nav>
    <a href="#0" class="cd-close">Close modal</a>
</div>
</body>
</html>
<script>
    $(function () {
        var totalfee = <%= totalmoney%>;
        var addrId = <% if(addr.length>0){%><%= addr[0].addr_id%><%}else {%><%= -1%><%}%>
        $('#payOrder').click(function () {
            if(addrId == -1){
                alert("请选择地址");
                return;
            }
            $.post('/order/payOrd',{},function (data) {
                var resobj = JSON.parse(data);
               if(resobj.code == 0){
                   function onBridgeReady(){
                       WeixinJSBridge.invoke(
                           'getBrandWCPayRequest', {
                               "appId":resobj.appId,     //公众号名称，由商户传入
                               "timeStamp":resobj.timeStamp,         //时间戳，自1970年以来的秒数
                               "nonceStr":resobj.nonceStr, //随机串
                               "package":resobj.package,
                               "signType":resobj.signType,         //微信签名方式：
                               "paySign":resobj.paySign //微信签名
                           },
                           function(res){
                               console.log(JSON.stringify(res));
                               if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                                   location.href = '/order/paySuccess?str='+resobj.nonceStr+'&addrId='+addrId;
                               }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                           }
                       );
                   }
                   if (typeof WeixinJSBridge == "undefined"){
                       if( document.addEventListener ){
                           document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                       }else if (document.attachEvent){
                           document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                           document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                       }
                   }else{
                       onBridgeReady();
                   }
               } else {
                   location.href = '/order/payError?addrId='+addrId+'&totalfee='+totalfee;
               }
            });
        });

        var ordId = 0;
        var is_bouncy_nav_animating = false;
        //弹出菜单
        $('.cd-bouncy-nav-trigger').on('click', function() {
            ordId = $(this).attr('id');
            triggerBouncyNav(true);
        });
        //关闭菜单
        $('.cd-bouncy-nav-modal .cd-close').on('click', function() {
            triggerBouncyNav(false);
        });
        $('.cd-bouncy-nav-modal').on('click', function(event) {
            if ($(event.target).is('.cd-bouncy-nav-modal')) {
                triggerBouncyNav(false);
            }
        });

        function triggerBouncyNav($bool) {
            //点击若没有动画
            if (!is_bouncy_nav_animating) {
                is_bouncy_nav_animating = true;
                //切换菜单动画
                $('.cd-bouncy-nav-modal').toggleClass('fade-in', $bool).toggleClass('fade-out', !$bool).find('li:last-child').one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function() {
                    $('.cd-bouncy-nav-modal').toggleClass('is-visible', $bool);
                    if (!$bool)
                        $('.cd-bouncy-nav-modal').removeClass('fade-out');
                    is_bouncy_nav_animating = false;
                });
                //判断css 动画是否开启..
                if ($('.cd-bouncy-nav-trigger').parents('.no-csstransitions').length > 0) {
                    $('.cd-bouncy-nav-modal').toggleClass('is-visible', $bool);
                    is_bouncy_nav_animating = false;
                }
            }
        }

        $('#cancel').click(function () {
            $.get('/order/updOrdState',{ordId:ordId,status:1},function (data) {
                var obj = JSON.parse(data);
                if(obj.code == 0){
                    iosOverlay({
                        text: "操作成功！ ",
                        duration: 2e3,
                        icon: "/images/tipsokico.png"
                    });
                }else {
                    iosOverlay({
                        text: "操作失败！ ",
                        duration: 2e3,
                        icon: "/images/erricon.png"
                    });
                }
                setTimeout(function () {
                    location.reload();
                },2000)
            })
        });

        $('#del').click(function () {
            $.get('/order/updOrdState',{ordId:ordId,status:9},function (data) {
                var obj = JSON.parse(data);
                if(obj.code == 0){
                    iosOverlay({
                        text: "操作成功！ ",
                        duration: 2e3,
                        icon: "/images/tipsokico.png"
                    });
                }else {
                    iosOverlay({
                        text: "操作失败！ ",
                        duration: 2e3,
                        icon: "/images/erricon.png"
                    });
                }
                setTimeout(function () {
                    location.reload();
                },2000)
            })
        });

    })
</script>